package com.ifuncat.demo.adminserverarthas.util;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

public class EncryptionUtils {
    public static final String encryption = "5fdb2b224cea4939";

    private static SymmetricCrypto SM4;

    /**
     * 获取SM4实例
     */
    private static SymmetricCrypto getSM4() {
        if (ObjectUtil.isEmpty(SM4)) {
            byte[] desKey = encryption.getBytes();
            SM4 = new SymmetricCrypto("SM4", desKey);
        }
        return SM4;
    }

    /**
     * SM4加密
     */
    public static String SM4Encrypt(String decryptStr) {
        return getSM4().encryptHex(decryptStr);
    }

    /**
     * SM4解密
     */
    public static String SM4Decrypt(String encryptStr) {
        return getSM4().decryptStr(encryptStr, CharsetUtil.CHARSET_UTF_8);
    }
}
